package com.baoteng.rbspy.model.privy;

import java.util.List;
import java.util.Optional;

import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import com.baoteng.rbspy.annotation.JsoupProperty;
import com.baoteng.rbspy.util.JsoupUtil;
import com.google.common.collect.Lists;

public class PrivyPO {

	@JsoupProperty(tag = "input[id=editFlag]")
	protected String editFlag;

	@JsoupProperty(tag = "input[id=prpCmainCommon.ext2]")
	protected String ext2;

	@JsoupProperty(tag = "input[id=configedRepeatTimesLocal]")
	protected String configedRepeatTimesLocal;

	/**
	 * 客户代码
	 */
	@JsoupProperty(tag = "input[id=hidden_index_insured]")
	protected String hidden_index_insured;

	List<PrivyItemPO> items;
	
	/**
	 * 关系人状态，如果用户提交的关系人名字和系统里不一致为invalid或者审核没有通过。一致为effect。
	 */
	protected String privyStatus;

	public String getEditFlag() {
		return editFlag;
	}

	public void setEditFlag(String editFlag) {
		this.editFlag = editFlag;
	}

	public String getExt2() {
		return ext2;
	}

	public void setExt2(String ext2) {
		this.ext2 = ext2;
	}

	public String getConfigedRepeatTimesLocal() {
		return configedRepeatTimesLocal;
	}

	public void setConfigedRepeatTimesLocal(String configedRepeatTimesLocal) {
		this.configedRepeatTimesLocal = configedRepeatTimesLocal;
	}

	public String getHidden_index_insured() {
		return hidden_index_insured;
	}

	public void setHidden_index_insured(String hidden_index_insured) {
		this.hidden_index_insured = hidden_index_insured;
	}

	public List<PrivyItemPO> getItems() {
		return items;
	}

	public void setItems(List<PrivyItemPO> items) {
		this.items = items;
	}

	public String getPrivyStatus() {
		return privyStatus;
	}

	public void setPrivyStatus(String privyStatus) {
		this.privyStatus = privyStatus;
	}

	public void parser(Element doc) {
		items = Optional.ofNullable(items).orElse(Lists.newArrayList());
		Element element = doc.getElementById("insertInsuredRow");
		if (element != null) {
			Elements elements = element.select("tbody>tr");
			elements.forEach(e -> {
				PrivyItemPO itemPO = new PrivyItemPO();
				JsoupUtil.newInstance().parse(e, itemPO);
				items.add(itemPO);
			});
		}
	}
}
